﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Simple.Contracts.Contracts;
using Simple.Contracts.Models;
using Simple.Contracts.Models.Common;
using Simple.WebAi.Authorizes;
using System.ComponentModel.DataAnnotations;

namespace Simple.WebAi.Controllers
{
    /// <summary>
    /// 账户
    /// </summary>
    [Route("api/account")]
    [ApiController]
    public class AccountController : ControllerBase
    {
        private readonly IAccountService _accountService;
        private readonly IConfiguration _configuration;
        private readonly ISmsService _smsService;

        /// <summary>
        /// 依赖注入
        /// </summary>
        /// <param name="accountService"></param>
        public AccountController(IAccountService accountService, IConfiguration configuration)
        {
            _accountService = accountService;
            _configuration = configuration;
        }

        /// <summary>
        /// 账号登录
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("login")]
        public async Task<Result<LoginDto>> Login(LoginInput input)
        {
            return await _accountService.Login(input);
        }

        /// <summary>
        /// 账号菜单
        /// </summary>
        /// <returns></returns>
        [HttpGet("menu/list")]
        [AccountAuthorize]
        public async Task<Result<List<MenuPageDto>>> MenuPageList()
        {
            return await _accountService.MenuPageList();
        }

        /// <summary>
        /// 账户功能
        /// </summary>
        /// <returns></returns>
        [HttpGet("auth/buttons")]
        [AccountAuthorize]
        public async Task<Result<Dictionary<string, List<string>>>> AuthButtons()
        {
            return await _accountService.AuthButtons();
        }

        /// <summary>
        /// 退出登录
        /// </summary>
        /// <returns></returns>
        [HttpPost("logout")]
        [AccountAuthorize]
        public async Task<Result<bool>> LogOut()
        {
            return Result<bool>.Success(true);
        }

        /// <summary>
        /// 发送登录验证码
        /// </summary>
        /// <param name="phone"></param>
        /// <returns></returns>
        [HttpPost("send-login-code")]
        public async Task<Result<bool>> SendLoginCode([FromForm][Required] string phone)
        {
            return await _accountService.SendLoginCode(phone);
        }
    }
}
